package com.xin.utils.reflection;

import javafx.geometry.Pos;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;

import java.lang.reflect.Method;

/**
 * 控制器反射工具类
 */
public class ControllerMethodUtils {

    /**
     * 获取控制器上方法上的请求路径
     * @param method
     * @return
     */
    public static String getUrl(Method method){
        if (method.getAnnotation(GetMapping.class)!=null){
            GetMapping annotation = method.getAnnotation(GetMapping.class);
            return annotation.value()[0];
        }
        else if (method.getAnnotation(PostMapping.class)!=null){
            PostMapping postMapping = method.getAnnotation(PostMapping.class);
            return postMapping.value()[0];
        }
        else if (method.getAnnotation(PutMapping.class)!=null){
            PutMapping putMapping = method.getAnnotation(PutMapping.class);
            return putMapping.value()[0];
        }
        else return method.getAnnotation(DeleteMapping.class).value()[0];
    }
}
